<template>
  <div class="giftSearch">
    <el-form
      :inline="true"
      :model="formData"
      class="demo-form-inline"
      ref="formData"
      style="width: 100%"
    >
      <el-form-item>
        <el-input v-model="formData.giftName" placeholder="礼包名称"></el-input>
      </el-form-item>
      <el-form-item>
        <el-select
          v-model="formData.gameId"
          filterable
          placeholder="输入游戏名搜索"
        >
          <el-option
            v-for="item in options"
            :key="item.id"
            :label="item.gameName"
            :value="item.id"
            style="width: 300px"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item v-if="giftType==1">
        <el-select
          v-model="formData.type"
          filterable
          placeholder="选择礼包类型"
        >
          <el-option
            v-for="item in typeoption"
            :key="item.id"
            :label="item.label"
            :value="item.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-date-picker
          v-model="formData.time"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          style="margin-top: 6px"
          value-format="yyyy-MM-dd"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <div style="display: inline-block" class="countInput">
          <el-form-item>
            <el-input
              v-model="formData.starCount"
              placeholder="礼包数"
            ></el-input>
          </el-form-item>
        </div>
        <div style="display: inline-block; margin-right: 5px">~</div>
        <div style="display: inline-block" class="countInput">
          <el-form-item>
            <el-input
              v-model="formData.endCount"
              placeholder="礼包数"
            ></el-input>
          </el-form-item>
        </div>
      </el-form-item>

      <el-form-item>
        <el-button
          type="primary"
          class="dataSearch"
          @click="dataSearch(formData)"
          style="margin-left: 50px"
          >搜索</el-button
        >
      </el-form-item>
      <el-form-item v-if="giftType==1">
        <el-button class="addNewgame" type="primary" @click="addActivity()"
          >添加礼包</el-button
        >
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import { getOptionList } from "@/api/gameManage";
export default {
  data() {
    return {
      formData: {
        gameId: "",
        giftName: "",
        time: [],
        page: 1,
        limit: 20,
        starCount: 0,
        endCount: "",
        type: "",
      },
      options: [],
      typeoption: [
        {
          id: 1,
          label: "普通礼包",
        },
        {
          id: 2,
          label: "累计充值礼包",
        },
        {
          id: 3,
          label: "限时累计充值礼包",
        },
      ],
      loading: false,
      
    };
  },
  props:{
    giftType:Number
  },
  mounted() {
    getOptionList().then((res) => {
      this.options = res.data.list;
    });
  },
  methods: {
    // 查询
    dataSearch() {
      this.$refs.formData.validate((valid) => {
        if (valid) {
          const startTime =
            this.formData.time == null || this.formData.time.length == 0
              ? ""
              : this.formData.time[0];
          const endTime =
            this.formData.time == null || this.formData.time.length == 0
              ? ""
              : this.formData.time[1];
          const obj = {
            giftName: this.formData.giftName,
            gameId: this.formData.gameId,
            startTime,
            endTime,
            page: 1,
            limit: 20,
            starCount: this.formData.starCount,
            endCount: this.formData.endCount,
            type: this.formData.type,
          };
          this.$store.commit("SET_SEARCH", obj);
          this.$emit("searchList", obj);
        }
      });
    },
    addActivity() {
      this.$emit("showaddGiftDialog");
    },
  },
};
</script>
<style lang="scss">
.giftSearch {
  width: 60%;
  margin-left: 30px;
  .countInput {
    .el-input {
      width: 80px;
    }
  }
  .el-select-dropdown__item {
    white-space: normal;
    height: auto;
  }
  .el-date-editor--daterange.el-input,
  .el-date-editor--daterange.el-input__inner,
  .el-date-editor--timerange.el-input,
  .el-date-editor--timerange.el-input__inner {
    width: 250px;
  }

  .el-form-item {
    margin-bottom: 0;
  }
  .el-button--primary {
    background-color: #409eff;
    border-color: #409eff;
  }
  .addNewgame,
  .dataSearch {
    padding: 0 15px;
    height: 30px;
    font-size: 13px;
  }
}

</style>